<?php
namespace App\Api\Appfc114;

use PhalApi\Api;
use PhalApi\Exception\BadRequestException;
use Auth\Api\Token as Token;
use App\Domain\Appfc114\Project as DomainProject;


/**
 * 新房接口服务
 *
 * @author: dogstar <chanzonghuang@gmail.com> 2014-10-04
 */

class Project extends Api {

    /**
     * token对象
     */
    protected $token;

    public function __construct()
    {
        //允许所有域名发起的跨域请求
        header('Access-Control-Allow-Origin: *');  //支持全域名访问，不安全，部署后需要固定限制为客户端网址
        //header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE'); //支持的http 动作
        //header('Access-Control-Allow-Headers:Authorization,content-type');  //响应头 请按照自己需求添加。
        //$this->di = \PhalApi\DI();
        //$this->token = new Token();
    }

	public function getRules() {
        return array(
            'getList' => ['city_code'=>['name' => 'city_code', 'type'=>'int', 'require' => true, 'desc' => '城市编码']],
            'hotList' => ['city_code'=>['name' => 'city_code', 'type'=>'int', 'require' => true, 'desc' => '城市编码'],
                          'digest'=>['name' => 'digest', 'type'=>'int', 'require' => true, 'desc' => '热门推荐']],
            'detail' =>  ['project_id'=>['name' => 'project_id', 'type'=>'int', 'require' => true, 'desc' => '项目id']],
            'projectBuild' => ['project_id'=>['name' => 'project_id', 'type'=>'int', 'require' => true, 'desc' => '项目id']],
            'projectNode' => ['project_id'=>['name' => 'project_id', 'type'=>'int', 'require' => true, 'desc' => '项目id']],
            'projectDynamic' => ['project_id'=>['name' => 'project_id', 'type'=>'int', 'require' => true, 'desc' => '项目id']],
            'projectPic' => ['project_id'=>['name' => 'project_id', 'type'=>'int', 'require' => true, 'desc' => '项目id']],
        );
	}

    /**
	 * 获取新房列表
     * @desc 获取新房列表 查询,分页,排序等
     * @return array data
	 * @return int time 当前时间戳
	 */
	public function getList() {
        //$this->user = $this->token->checkToken();
        error_log("getList!", 0);

        $Project = new DomainProject();
        $data = $Project->getlist();
        return $data;
	}

    /**
     * 热门楼盘
     * @desc 获取新房列表 查询,分页,排序等
     * @return array data
     * @return int time 当前时间戳
     */
    public function hotList(){
        error_log("getList!", 0);

        $Project = new DomainProject();
        $data = $Project->getlist();
        foreach ($data as $key=>$item){
            $data[$key]['pm'] = $Project->projectPmInfo('20301',$item['id']);
        }
        return $data;
    }

    /**
     * 获取项目详情

     * @return array data 客户信息
     * @return int time 当前时间戳
     */
    public function detail()
    {
        //$this->user = $this->token->checkToken();
        error_log("projectDetail!", 0);
        //主表数据
        $params =  \PhalApi\DI()->request->getAll();
        //插入主表数据
        $domain = new DomainProject();
        $data = $domain->detail($params["project_id"]);

        return $data;

    }

    /**
     * 获取项目楼栋
     * @desc 获取项目楼栋
     * @return array data
     * @return int time 当前时间戳
     */
    public function projectBuild() {
        //$this->user = $this->token->checkToken();
        error_log("projectBuild!", 0);

        $Project = new DomainProject();
        $data = $Project->build();
        return $data;
    }

    /**
     * 获取新房户型
     * @desc 获取新房户型
     * @return array data
     * @return int time 当前时间戳
     */
    public function projectMode() {
        //$this->user = $this->token->checkToken();
        error_log("projectMode!", 0);

        $Project = new DomainProject();
        $data = $Project->projectMode();
        return $data;
    }

    /**
     * 获取项目动态
     * @desc 获取项目动态
     * @return array data
     * @return int time 当前时间戳
     */
    public function projectDynamic() {
        //$this->user = $this->token->checkToken();
        error_log("projectDynamic!", 0);

        $Project = new DomainProject();
        $data = $Project->projectDynamic();
        return $data;
    }

    /**
     * 获取项目图片
     * @desc 获取项目图片
     * @return array data
     * @return int time 当前时间戳
     */
    public function projectPic() {
        //$this->user = $this->token->checkToken();
        error_log("projectPic!", 0);

        $Project = new DomainProject();
        $data = $Project->projectPic();
        return $data;
    }

}
